﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.Configuration;
namespace LibraryReservation
{
    public sealed class CreateRequest:CodeActivity
    {
        public InArgument<string> Title { get; set; }
        public InArgument<string> Author { get; set; }
        public InArgument<string> ISBN { get; set; }
        public OutArgument<ReservationRequest> Request { get; set; }
        public OutArgument<string> RequestAddress { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            AppSettingsSection app = (AppSettingsSection)config.GetSection("appSettings");

            ReservationRequest r = new ReservationRequest(
                Title.Get(context),
                Author.Get(context),
                ISBN.Get(context),
                new Branch
                {
                    BranchName = app.Settings["Branch Name"].Value,
                    BranchID = new Guid(app.Settings["ID"].Value),
                    Address = app.Settings["Address"].Value
                }
            );
            Request.Set(context, r);
            RequestAddress.Set(context, app.Settings["Request Address"].Value);
        }

    }
}
